﻿using System.Collections.Generic;
using UnityEditor;
using UnityEngine;


namespace Manox.Libs.ODB
{
    /// <summary>
    /// ODB inspector item.
    /// </summary>
    public abstract class ODBInspectorItem
    {
        /// <summary>Children.</summary>
        public List<ODBInspectorItem> Children;


        /// <summary>
        /// Cosntructor.
        /// </summary>
        public ODBInspectorItem()
        {
            this.Children = new List<ODBInspectorItem>();
        }

        /// <summary>
        /// On inspector GUI.
        /// </summary>
        public virtual void OnInspectorGUI()
        {

        }

        /// <summary>
        /// Process children.
        /// </summary>
        public virtual void ProcessChildren()
        {
            for (int i = 0; i < this.Children.Count; i++)
                this.Children[i].OnInspectorGUI();
        }      
    }


    /// <summary>
    /// ODB inspector item group.
    /// </summary>
    public class ODBInspectorItemGroup : ODBInspectorItem
    {
        /// <summary>Open.</summary>
        public bool Open;
        /// <summary>Group name.</summary>
        public string GroupName;


        /// <summary>
        /// Constructor.
        /// </summary>
        public ODBInspectorItemGroup(string groupName)
            : base()
        {
            this.Open = false;
            this.GroupName = groupName;
        }

        /// <summary>
        /// On inspector GUI.
        /// </summary>
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            this.Open = EditorGUILayout.Foldout(this.Open, this.GroupName);

            if (this.Open)
                this.ProcessChildren();           
        }
    }
}
